package database

import (
	"RocFamilySystem/config"
	"RocFamilySystem/tools/container"
	"fmt"
	"gorm.io/driver/mysql"
	_ "gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/schema"
	"log"
)

func InitMysqlDatabase() {
	conf := config.GlobalConfig.DataBase
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", conf.Username, conf.Password, conf.Host, conf.Port, conf.Db)
	db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{
		NamingStrategy: schema.NamingStrategy{
			SingularTable: true, //配置单表
		},
	})
	if err != nil {
		log.Panicln("连接MYSQL出错：", err.Error())
	}
	db = db.Debug()
	container.PushContainer(db)
}
